import 'package:flame/game.dart';
import 'package:flutter/material.dart';
import 'package:hero_back/study/flutter_game_flame/day005/menu/pause.dart';

import '../game.dart';

class MainMenu extends StatelessWidget {
  const MainMenu({Key? key}) : super(key: key);
  final TextStyle shadowStyle = const TextStyle(fontSize: 30, shadows: [
    Shadow(color: Colors.white, blurRadius: 10),
  ]);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Wrap(
          spacing: 20,
          direction: Axis.vertical,
          crossAxisAlignment: WrapCrossAlignment.center,
          children: [
            Text(
              'Adventurer',
              style: shadowStyle,
            ),
            ElevatedButton(
                onPressed: () {
                  _doPlay(context);
                },
                child: const Text('开 始')),
            ElevatedButton(onPressed: _toOptions, child: const Text('设 置'))
          ],
        ),
      ),
    );
  }

  void _doPlay(context) {
    Navigator.of(context).pushReplacement(
        MaterialPageRoute(builder: (ctx) => const GameWorld()));
  }

  void _toOptions() {}
}

class GameWorld extends StatelessWidget {
  const GameWorld({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GameWidget<HeroGame>(
      game: HeroGame(),
      overlayBuilderMap: {PauseMenu.menuId: (_, game) => PauseMenu(game: game)},
    );
  }
}
